from rest_framework.generics import GenericAPIView
from rest_framework.response import Response
from djangoProject.celery import app as celery_app


class TasksAPIViews(GenericAPIView):
    pagination_class = None

    def get(self, request, *args, **kwargs):
        tasks = {}
        for task in celery_app.tasks:
            if not task.startswith('celery.'):
                tasks.update({task.split(':')[1]: task.split(':')[0]})
        return Response({
            "code": 200,
            "data": {"data": tasks},
            "message": "OK",
        })
